package script.db

databaseChangeLog(logicalFilePath: 'script/db/hpfm_cusz_unit_con_line.groovy') {
    changeSet(author: "hzero@hand-china.com", id: "2022-07-14-hpfm_cusz_unit_con_line") {
        def weight = 1
        if (helper.isSqlServer()) {
            weight = 2
        } else if (helper.isOracle()) {
            weight = 3
        }
        if (helper.dbType().isSupportSequence()) {
            createSequence(sequenceName: 'hpfm_cusz_unit_con_line_s', startValue: "1")
        }
        createTable(tableName: "hpfm_cusz_unit_con_line", remarks: "个性化单元条件组行") {
            column(name: "con_line_id", type: "bigint", autoIncrement: true, remarks: "表ID，主键，供其他表做外键") { constraints(primaryKey: true) }
            column(name: "condition_id", type: "bigint", remarks: "单元条件ID") { constraints(nullable: "false") }
            column(name: "line_number", type: "int", remarks: "行编号") { constraints(nullable: "false") }
            column(name: "source_type", type: "varchar(" + 30 * weight + ")", remarks: "来源值类型") { constraints(nullable: "false") }
            column(name: "source_value", type: "varchar(" + 120 * weight + ")", remarks: "来源值") { constraints(nullable: "false") }
            column(name: "condition_type", type: "varchar(" + 30 * weight + ")", remarks: "条件") { constraints(nullable: "false") }
            column(name: "target_type", type: "varchar(" + 30 * weight + ")", remarks: "目标值类型") { constraints(nullable: "false") }
            column(name: "target_value", type: "varchar(" + 120 * weight + ")", remarks: "目标值") { constraints(nullable: "false") }
            column(name: "tenant_id", type: "bigint", defaultValue: "0", remarks: "租户ID") { constraints(nullable: "false") }
            column(name: "created_by", type: "bigint", defaultValue: "-1", remarks: "创建人") { constraints(nullable: "false") }
            column(name: "last_updated_by", type: "bigint", defaultValue: "-1", remarks: "最近更新人") { constraints(nullable: "false") }
            column(name: "creation_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "创建时间") { constraints(nullable: "false") }
            column(name: "last_update_date", type: "datetime", defaultValueComputed: "CURRENT_TIMESTAMP", remarks: "最近更新时间") { constraints(nullable: "false") }
            column(name: "object_version_number", type: "bigint", defaultValue: "1", remarks: "行版本号，用来处理锁") { constraints(nullable: "false") }
        }

        addUniqueConstraint(columnNames: "condition_id,line_number", tableName: "hpfm_cusz_unit_con_line", constraintName: "hpfm_cusz_unit_con_line_u1")
    }
}